package mc0457;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

public class Main {
    static final int N = 500010;
    static final int mod = 998244353;
    static int n, q;
    static long[] a = new long[N];
    static long[] sum1 = new long[N];
    static long[] sum2 = new long[N];
    
    //输入优化模板开始
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer st = new StreamTokenizer(br);
	static int rd() throws IOException {
		st.nextToken();
		return (int) st.nval;
	}
	//输入优化模板结束
	
	//输出优化
	static StringBuilder sb = new StringBuilder();

    public static void main(String[] args) throws IOException {
        
        n = rd();
        q = rd();

        for (int i = 1; i <= n; i++) {
            a[i] = rd();
        }

        // 预处理前缀和数组
        for (int i = 1; i <= n; i++) {
            sum1[i] = (sum1[i - 1]% mod + a[i]% mod) % mod;
            sum2[i] = (sum2[i - 1]% mod + (i + 1) * a[i] % mod) % mod;
        }

        while (q-- > 0) {
            int l = rd();
            int r = rd();

            long s1 = (sum1[r] - sum1[l - 1] + mod) % mod;
            long s2 = (sum2[r] - sum2[l - 1] + mod) % mod;

            //取模减法运算可能出现负数的结果，需要加上mod再取模变正
            long ans = (s2 - l * s1 % mod + mod) % mod;
            System.out.println(ans);
        }
    }
}
